package com.ruoyi.edit.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.edit.domain.CoursePackageV2;
import com.ruoyi.edit.service.ICoursePackageV2Service;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公共课程详情Controller
 * 
 * @author qiufeng
 * @date 2022-11-07
 */
@Controller
@RequestMapping("/system/coursePackageV2")
public class CoursePackageV2Controller extends BaseController
{
    private String prefix = "system/coursePackageV2";

    @Autowired
    private ICoursePackageV2Service coursePackageV2Service;

    @GetMapping()
    public String coursePackageV2()
    {
        return prefix + "/coursePackageV2";
    }

    /**
     * 查询公共课程详情列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CoursePackageV2 coursePackageV2)
    {
        startPage();
        List<CoursePackageV2> list = coursePackageV2Service.selectCoursePackageV2List(coursePackageV2);
        return getDataTable(list);
    }


    @PostMapping("/listV2")
    @ResponseBody
    public TableDataInfo listV2(CoursePackageV2 coursePackageV2)
    {
        startPage();
        List<CoursePackageV2> list = coursePackageV2Service.selectCoursePackageV2ListV2(coursePackageV2);
        return getDataTable(list);
    }


    /**
     * 查询公共课程详情列表
     */
    @PostMapping("/list_v1")
    @ResponseBody
    public TableDataInfo listV1(String ids)
    {
        startPage();
        List<CoursePackageV2> list = coursePackageV2Service.selectCoursePackageV2ByIds(ids);
        return getDataTable(list);
    }
    /**
     * 导出公共课程详情列表
     */
    @Log(title = "公共课程详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CoursePackageV2 coursePackageV2)
    {
        List<CoursePackageV2> list = coursePackageV2Service.selectCoursePackageV2List(coursePackageV2);
        ExcelUtil<CoursePackageV2> util = new ExcelUtil<CoursePackageV2>(CoursePackageV2.class);
        return util.exportExcel(list, "公共课程详情数据");
    }

    /**
     * 新增公共课程详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公共课程详情
     */
    @Log(title = "公共课程详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CoursePackageV2 coursePackageV2)
    {
        return toAjax(coursePackageV2Service.insertCoursePackageV2(coursePackageV2));
    }

    /**
     * 修改公共课程详情
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        CoursePackageV2 coursePackageV2 = coursePackageV2Service.selectCoursePackageV2ById(id);
        mmap.put("coursePackageV2", coursePackageV2);
        return prefix + "/edit";
    }

    /**
     * 修改保存公共课程详情
     */
    @Log(title = "公共课程详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CoursePackageV2 coursePackageV2)
    {
        return toAjax(coursePackageV2Service.updateCoursePackageV2(coursePackageV2));
    }

    /**
     * 删除公共课程详情
     */
    @Log(title = "公共课程详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(coursePackageV2Service.deleteCoursePackageV2ByIds(ids));
    }

    /**
     * 课程详情
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/parentPackages")
    public String parentPackages(String id, ModelMap mmap)
    {
        mmap.put("id", id);
        return prefix + "/parentPackages";
    }

}
